package org.sabeot.enlistme.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.RequestScoped;

import org.sabeot.enlistme.hibernate.dto.UserDTO;
import org.sabeot.enlistme.service.UserService;
import org.sabeot.enlistme.web.bean.UserBean;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller("viewUsersController")
@RequestScoped
public class ViewUsersController {

	@Autowired
	UserService userService;
	
	@Autowired
	private UserBean user;
	
	private List<UserBean> allUsers;
	
	public List<UserBean> getAllUsers(){
		List<UserDTO> dtoUsers = userService.getAllUsers();
		
		if(dtoUsers==null || dtoUsers.isEmpty()){
			return null;
		}
		
		List<UserBean> resultList = new ArrayList<UserBean>();
		
		for(UserDTO u : dtoUsers){
			UserBean target = new UserBean();
			BeanUtils.copyProperties(u, target);
			resultList.add(target);
		}
		
		return resultList;
	}
	
}
